<template>
    <div class="chartsContainer">
        <div class="header">
            <div class="left">
                <span :class="{active:recommendStore.hotId ==item.id}" v-for="(item,index) in hotList"
                    @click="changeHot(item,index)" :key="item.id">{{item.name}}</span>

            </div>
            <div class="right" @click="flag=!flag">
                <span>筛选</span>
                <svg :class="{select: flag}" t="1666100005311" class="icon" viewBox="0 0 1024 1024" version="1.1"
                    xmlns="http://www.w3.org/2000/svg" p-id="35224" width="14" height="14">
                    <path
                        d="M517.688889 796.444444c-45.511111 0-85.333333-17.066667-119.466667-51.2L73.955556 381.155556c-22.755556-22.755556-17.066667-56.888889 5.688888-79.644445 22.755556-22.755556 56.888889-17.066667 79.644445 5.688889l329.955555 364.088889c5.688889 5.688889 17.066667 11.377778 28.444445 11.377778s22.755556-5.688889 34.133333-17.066667l312.888889-364.088889c22.755556-22.755556 56.888889-28.444444 79.644445-5.688889 22.755556 22.755556 28.444444 56.888889 5.688888 79.644445L637.155556 739.555556c-28.444444 39.822222-68.266667 56.888889-119.466667 56.888888 5.688889 0 0 0 0 0z"
                        p-id="35225" fill="#b1b5c1"></path>
                </svg>
            </div>
        </div>

        <div class="main" v-show="!flag">
            <el-row v-for="(c,index) in recommendStore.charts" :key="index">

                <el-col :span="2">
                    <div class="title">{{c.label}}：</div>
                </el-col>
                <el-col :span="22">
                    <div class="categoryDance" :class="{active:item.select}" @click="checkHobby(c,item,index)"
                        v-for="(item,index) in c.choises" :key="item.id">{{item.name}}</div>
                </el-col>

            </el-row>

            <div class="reset" @click="reset" v-show="!(recommendStore.avocation.length==0&&recommendStore.contentType==0)">重置</div>
        </div>
    </div>
</template>

<script setup lang="ts">

import { useRouter, useRoute } from "vue-router"
import { reactive, ref, onMounted, watch } from 'vue'
import useRecommendStore from "@/stores/recommend";
import { ElMessage } from "element-plus";
const recommendStore = useRecommendStore();
const router = useRouter();
const route = useRoute();
const emit = defineEmits(["getList"]);
// 决定筛选部分的显示与隐藏
const flag = ref(true);
const hotList = ref([
    {
        id: 1,
        name: "综合榜",
        value: "integrated"
    },
    {
        id: 2,
        name: "热练榜",
        value: "popTraining"
    }, {
        id: 3,
        name: "新锐榜",
        value: "newcomer"
    }, {
        id: 4,
        name: "最新",
        value: "lastest"
    }
])





// 切换榜单
const changeHot = (item, index) => {
    if (recommendStore.hotId == item.id) {
        return;
    }
    recommendStore.hotId = item.id;
    recommendStore.hotName = item.value;
    recommendStore.clearData();
    // recommendStore.avocation.forEach(item=>item.select = false);
    // recommendStore.contentType.forEach(item=>item.select = false); 


    emit("getList");
    // if(route)
    //     recommendStore.

}
// 点击榜单内兴趣爱好的回调
const checkHobby = (c, item, index) => {
    console.log("仓库的计算属性", recommendStore.avocation);
    // 
    if (recommendStore.avocation.length >= 3 && c.name == "avocation" && !item.select) {
        ElMessage.info("同一筛选条件最多选择3个！");
        return;
    }
    item.select = !item.select;
    recommendStore.clearData();
    console.log("为什么没有清除数据");

    emit("getList");

}






const filterData = async () => {
    await recommendStore.getCharts();
    if (route.path == "/index/specialTopic") {
        console.log("过滤中");
        recommendStore.charts = recommendStore.charts.filter(item => item.name == "avocation")
    }
}

watch(() => route.path, () => {
    recommendStore.hotId = 1;
    recommendStore.hotName = "integrated ";
    recommendStore.avocation.forEach(item => item.select = false);
    recommendStore.contentType.forEach(item => item.select = false);
    filterData();

}, { immediate: true })



// 重置数据
const reset = ()=>{
    recommendStore.avocation.forEach(item => item.select = false);
    recommendStore.contentType.forEach(item => item.select = false);
    filterData();
}




onMounted(() => {
    filterData();

})
</script>

<style scoped>
.chartsContainer {
    width: 1200px;
    margin: 0 auto;
    cursor: pointer;
}

.chartsContainer .header {
    width: 100%;
    height: 68px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chartsContainer .header .left {
    padding: 25px 30px;
    font-size: 14px;
    color: #7d8090;
}

.chartsContainer .header .left span+span {
    margin-left: 60px;

}

.chartsContainer .header .left span:hover,
.chartsContainer .header .left .active {
    color: #f93684;
}

.chartsContainer .header .right {
    height: 36px;
    border-radius: 18px;
    background: #e9ecec;
    line-height: 36px;
    color: #7d8090;
    font-size: 16px;
    padding-left: 20px;
    padding-right: 10px;
    display: flex;
    align-items: center;
}

.chartsContainer .header .right svg {
    margin-left: 5px;
    display: block;
    opacity: 0;
}

.chartsContainer .header .right .select {
    opacity: 1;
}

/* 展开筛选框 */
.chartsContainer .main {
    padding: 26px 30px;
    position: relative;
}

.chartsContainer .main .categoryDance {
    display: inline-block;
    cursor: pointer;
    font-size: 14px;
    border-radius: 4px;
    padding: 8px 13px;
    user-select: none;
    margin-right: 24px;
    margin-bottom: 10px;
    color: #7d8090;
}

.chartsContainer .main .categoryDance.active {
    color: #fff;
    background-color: #f93684;

}

.chartsContainer .main .title {
    padding: 7px;
    color: #b1b5c1;
    font-size: 14px;
}

.chartsContainer .main .reset {
    position: absolute;
    right: 30px;
    top: 33px;
    font-size: 14px;
    color: #f93684;


}

.el-row {
    margin-bottom: 10px;
}

.el-row:last-child {
    margin-bottom: 0;
}
</style>